from rest_framework.decorators import action
from rest_framework.permissions import IsAdminUser, DjangoModelPermissions
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from django.contrib.auth.models import Permission,ContentType

from meiduo_admin.serializers.permissions import PermissionSerializer, ContentTypeSerializer
from meiduo_admin.utils import PageNum


class PermissionView(ModelViewSet):
    queryset = Permission.objects.all()
    serializer_class = PermissionSerializer
    pagination_class = PageNum
    permission_classes = [DjangoModelPermissions,IsAdminUser]



    def content_types(self,request):
        # 1.获取所有权限类型
        contentype=ContentType.objects.all()
        # 2.返回权限类型
        ser=ContentTypeSerializer(contentype,many=True)
        return Response(ser.data)